﻿using AxWMPLib;
using DevExpress.XtraEditors;
using Lamex.Base;
using Lamex.Common;
using Lamex.Library.UserCotrolUI;
using System;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace Lamex.mMES.Common
{
    /// <summary>
    /// 2020-1-15
    /// </summary>
    public class RefreshList
    {
        public static void InitLoadUI(string UserName, AxWindowsMediaPlayer axWindowsMediaPlayer1, DevExpress.XtraEditors.ProgressBarControl progressBar, PanelControl pcBottom, DataTable dtShowHeader, string StationName, bool IsPress)
        {
            try
            {
                ShowProductSumProgressBar(progressBar);

                Lamex.Common.IniFile ini = new IniFile(Application.StartupPath + "\\config\\SavePath.ini");
                string VedioPath = ini.IniReadValue("Path Configuration", "VedioPath").ToString();

                axWindowsMediaPlayer1.uiMode = "None";
                axWindowsMediaPlayer1.currentPlaylist.appendItem(axWindowsMediaPlayer1.newMedia(VedioPath));
                axWindowsMediaPlayer1.settings.setMode("loop", true);
                axWindowsMediaPlayer1.settings.mute = true;
                axWindowsMediaPlayer1.Ctlcontrols.play();

                LoadGroupList( UserName,  pcBottom,  dtShowHeader,  StationName,  IsPress);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }
        public static void RefreshListUI(string UserName, LabelControl lb_Name1, LabelControl lb_Name2, LabelControl LabelControl1, PictureBox picTop1, PictureBox picTop2,PictureBox picTop3, DataTable dtShowHeader, PanelControl pcBottom,PanelControl pcMid_L, int maxStandertime, int minStandertime, int standertime, int productTime, double iCycletime,string txtPartBarCode, bool IsPress)
        {

            InitLoad( UserName,  lb_Name1,  lb_Name2,  LabelControl1,  picTop1,  picTop2, picTop3, txtPartBarCode);
            ShowProcessList(UserName, dtShowHeader, pcBottom, pcMid_L, maxStandertime,   minStandertime,  standertime,  productTime, iCycletime,  IsPress);
        }

        public static void ResizePanel(DataTable dtShowHeader,PanelControl pcBottom)
        {
            int pcBottom_W = pcBottom.Width;
            int sum = dtShowHeader.Rows.Count;
            foreach (Control g in pcBottom.Controls)
            {
                if (g is GroupControl)
                {
                    GroupControl uc = g as GroupControl;
                    uc.Width = pcBottom_W / sum;
                }
            }
        }
        
        private static void ShowProductSumProgressBar(ProgressBarControl progressBar)
        {
            progressBar.Visible = true;
            progressBar.Properties.Minimum = 0;
            progressBar.Properties.Maximum = 100;
            progressBar.Properties.Step = 10;
            progressBar.Properties.ProgressViewStyle = DevExpress.XtraEditors.Controls.ProgressViewStyle.Solid;
            progressBar.Position = 0;
            progressBar.Properties.ShowTitle = true;
            progressBar.Properties.PercentView = true;

            string startime = "2019-11-12 08:00:00";
            DateTime time = Convert.ToDateTime(startime);
            TimeSpan span = DateTime.Now.Subtract(time);
            progressBar.Position = span.Hours * 10;

        }

        private static void LoadGroupList(string UserName,PanelControl pcBottom,DataTable dtShowHeader,string StationName, bool IsPress)
        {
            #region"生成显示控件"
            pcBottom.Controls.Clear();
            if (IsPress)
            {
                int i = dtShowHeader.Rows.Count;
                foreach (DataRow dr in dtShowHeader.Rows)
                {

                    
                    string Path = @"\\tx-fs10\TX-FS1\LAMEX\MES\SysSource\Image\Quality\" + UserName + @"\" + StationName + "_0" + i.ToString() + ".PNG";
                    GroupControl g = new GroupControl();
                    g.Name = "gc" + i.ToString();
                    g.Text = dr["LOCATION_NAME"].ToString();
                    
                    g.Dock = DockStyle.Left;
                    g.RightToLeft = RightToLeft.No;
                    g.ShowCaption = true;
                    g.AutoSize = false;
                    g.AppearanceCaption.Options.UseTextOptions = true;
                    g.AppearanceCaption.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    g.LookAndFeel.UseDefaultLookAndFeel = false;
                    PictureBox pic = new System.Windows.Forms.PictureBox();
                    pic.Dock = System.Windows.Forms.DockStyle.Fill;
                    pic.Location = new System.Drawing.Point(2, 21);
                    pic.Name = dr["LOCATION_NAME"].ToString()+i.ToString();
                    pic.Size = new System.Drawing.Size(130, 158);
                    pic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
                    pic.TabIndex = i;
                    pic.Name ="pic"+ i.ToString();
                    pic.TabStop = false;
                    pic.Visible = true;
                    if (File.Exists(Path))
                    {
                        pic.Load(Path);
                    }
                    //this.picProcess2.DoubleClick += new System.EventHandler(this.picProcess2_DoubleClick);
                    FrmSeatControlUI uc = new Lamex.Library.UserCotrolUI.FrmSeatControlUI();
                    uc.Dock = System.Windows.Forms.DockStyle.Fill;
                    uc.Location = new System.Drawing.Point(2, 21);
                    uc.Size = new System.Drawing.Size(130, 158);
                    uc.TabIndex = i;
                    uc.Visible = false;
                    //uc.DoubleClick += new System.EventHandler(frmSeatControlUI2_DoubleClick);
                    uc.Tag = dr["LOCATION_NAME"].ToString();
                    uc.Name = dr["LOCATION_NAME"].ToString();
                    g.Controls.Add(uc);
                    g.Controls.Add(pic);
                    pcBottom.Controls.Add(g);
                    i--;
                }

            }
            else
            {
                pcBottom.Controls.Clear();

                int i = 0;
                foreach (DataRow dr in dtShowHeader.Rows)
                {
                    GroupControl g = new GroupControl();
                    g.Name = "gc" + 1;
                    g.Text = dr["LOCATION_NAME"].ToString() + "实时产量";
                    g.Dock = DockStyle.Left;
                    g.RightToLeft = RightToLeft.No;
                    g.ShowCaption = true;
                    g.AutoSize = false;
                    g.AppearanceCaption.Options.UseTextOptions = true;
                    g.AppearanceCaption.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    g.LookAndFeel.UseDefaultLookAndFeel = false;
                    LabelControl lb = new LabelControl();
                    lb.Appearance.Font = new System.Drawing.Font("Tahoma", 50F, System.Drawing.FontStyle.Bold);
                    lb.Appearance.ForeColor = System.Drawing.Color.Blue;
                    lb.Appearance.Options.UseFont = true;
                    lb.Appearance.Options.UseForeColor = true;
                    lb.Appearance.Options.UseTextOptions = true;
                    lb.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                    lb.AutoSizeMode = DevExpress.XtraEditors.LabelAutoSizeMode.None;
                    lb.Dock = System.Windows.Forms.DockStyle.Fill;
                    lb.LineLocation = DevExpress.XtraEditors.LineLocation.Center;
                    lb.LineStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                    lb.Text = "0";
                    lb.Name = dr["LOCATION_NAME"].ToString();
                    //p.Controls.Add(lb);
                    g.Controls.Add(lb);
                    pcBottom.Controls.Add(g);
                    i++;
                }
            }
            #endregion
        }
        /// <summary>
        /// 加载用户和产品数据
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="lb_Name1"></param>
        /// <param name="lb_Name2"></param>
        /// <param name="LabelControl1"></param>
        /// <param name="picTop1"></param>
        /// <param name="picTop2"></param>
        public static void InitLoad(string UserName, LabelControl lb_Name1, LabelControl lb_Name2, LabelControl LabelControl1, PictureBox picTop1, PictureBox picTop2,PictureBox picTop3, string txtPartBarCode)
        {
            try
            {
                string strP01 = UserName + "_01";
                string strP02 = UserName + "_02";
                DataTable dtWorkInfo = Lamex.Base.BaseBuildSql.GetDataTableBySql(@"select  a.*,c.*  from [dbo].[HR_Station_Info] a 
                                                                                left join[dbo].[HR_Location_Record] b on b.LOCATION_CODE = a.LOCATION_CODE
                                                                                left join[dbo].[HR_Workers_Info] c on c.WORKER_NO = b.DUTY_OPERATOR
                                                                                where a.STATION_NAME = '" + UserName + "' and(a.LOCATION_CODE = '" + strP01 + "' or a.LOCATION_CODE = '" + strP02 + "') ");

                if (dtWorkInfo.Rows.Count != 0)
                {
                    //优先加载加载图片
                    if (dtWorkInfo.Rows[0]["PHOTO"].ToString() != "")
                    {
                        lb_Name1.Visible = false;
                        picTop1.Visible = true;
                        byte[] image1 = (byte[])dtWorkInfo.Rows[0]["PHOTO"];
                        picTop1.Image = Lamex.Common.DataConverter.ByteToImg(image1);
                        lb_Name1.Text = dtWorkInfo.Rows[0]["WORKER_NAME"].ToString();

                    }
                    else
                    {
                        lb_Name1.Visible = true;
                        picTop1.Visible = false;
                        lb_Name1.Text = dtWorkInfo.Rows[0]["WORKER_NAME"].ToString();

                    }

                    if (dtWorkInfo.Rows[1]["PHOTO"].ToString() != "")
                    {
                        lb_Name2.Visible = false;
                        picTop2.Visible = true;
                        byte[] image2 = (byte[])dtWorkInfo.Rows[1]["PHOTO"];
                        picTop2.Image = Lamex.Common.DataConverter.ByteToImg(image2);
                        lb_Name2.Text = dtWorkInfo.Rows[1]["WORKER_NAME"].ToString();


                    }
                    else
                    {
                        lb_Name2.Visible = true;
                        picTop2.Visible = false;
                        lb_Name2.Text = dtWorkInfo.Rows[1]["WORKER_NAME"].ToString();
                        picTop2.Load(@"\\tx-fs10\tx-fs1\LAMEX\MES\SysSource\Image\Product\MES_HR_TX00274.jpg");

                    }
                }

                DataTable dtDuty = Lamex.Base.BaseBuildSql.GetDataTableBySql(@"
                                                                               select * from [dbo].[HR_Station_Info] a 
                                                                                left join  HR_Location_Record b on b.LOCATION_CODE=a.LOCATION_CODE
                                                                                left join HR_Workers_Info c on c.WORKER_NO=b.DUTY_OPERATOR
                                                                                 where STATION_NAME = '" + UserName + "'");
                if (dtDuty.Rows.Count != 0)
                {
                    string strName = "";
                    int maxLength = 0;
                    foreach (DataRow dr in dtDuty.Rows)
                    {
                        if (dr["LOCATION_NAME"].ToString().Length > maxLength)
                        {
                            maxLength = dr["LOCATION_NAME"].ToString().Length;
                        }
                    }


                    foreach (DataRow dr in dtDuty.Rows)
                    {
                        int colLength = dr["LOCATION_NAME"].ToString().Length;
                        int blankLength = maxLength - colLength;
                        string strBlank = "";
                        int m = 0;
                        for (int i = 0; i < blankLength; i++)
                        {
                            strBlank += " ";
                            m = 1;
                        }
                        if (m == 1)
                            strName += "   " + strBlank + dr["LOCATION_NAME"].ToString() + "： " + dr["WORKER_NAME"].ToString() + "\r\n";
                        else
                            strName += " " + dr["LOCATION_NAME"].ToString() + "： " + dr["WORKER_NAME"].ToString() + "\r\n";
                        LabelControl1.Text = strName;
                    }
                }



                ///加载产品
                string path = @"\\Tx-fs10\tx-fs1\LAMEX\MES\SysSource\Image\Product\" + txtPartBarCode.Trim().Replace("\r", "") + ".jpg";
                if (File.Exists(path))
                {

                    DataTable dtDutyProduct = Lamex.Base.BaseBuildSql.GetDataTableBySql(@"
                                                                               select a.*,c.* from [dbo].[HR_Station_Info] a 
                                                                                left join  HR_Location_Record b on b.LOCATION_CODE=a.LOCATION_CODE
                                                                                left join HR_Workers_Info c on c.WORKER_NO=b.DUTY_OPERATOR
                                                                                 where STATION_NAME = '" + UserName + "'");
                    if (dtDutyProduct.Rows.Count != 0)
                    {
                        string strName = "";
                        int maxLength = dtDutyProduct.AsEnumerable().SelectMany(row => row.ItemArray.OfType<string>()).Max(o => o.Length);

                        foreach (DataRow dr in dtDutyProduct.Rows)
                        {
                            int colLength = dr["LOCATION_NAME"].ToString().Length;
                            int blankLength = maxLength - colLength;
                            string strBlank = "";
                            for (int i = 0; i < blankLength; i++)
                            {
                                strBlank += " ";
                            }
                            strName += strBlank + dr["LOCATION_NAME"].ToString() + "： " + dr["WORKER_NAME"].ToString() + "\r\n";
                        }
                        LabelControl1.Text = strName;
                    }

                    //string seatPath = @"\\tx-fs10\tx-fs1\LAMEX\MES\SysSource\Image\Product\MES_PD_S08_Array.jpg";
                    string seatPath = path;
                    if (File.Exists(seatPath))
                    {
                        picTop3.Visible = true;
                        LabelControl1.Visible = false;
                        picTop3.Load(seatPath);
                        //picProcess1.Load(QualityPath1);
                    }
                }
                else
                {
                    DataTable dtDutyProduct = Lamex.Base.BaseBuildSql.GetDataTableBySql(@"
                                                                               select a.*,c.* from [dbo].[HR_Station_Info] a 
                                                                                left join  HR_Location_Record b on b.LOCATION_CODE=a.LOCATION_CODE
                                                                                left join HR_Workers_Info c on c.WORKER_NO=b.DUTY_OPERATOR
                                                                                 where STATION_NAME = '" + UserName + "'");
                    if (dtDutyProduct.Rows.Count != 0)
                    {
                        string strName = "";
                        int maxLength = dtDutyProduct.AsEnumerable().SelectMany(row => row.ItemArray.OfType<string>()).Max(o => o.Length);

                        foreach (DataRow dr in dtDutyProduct.Rows)
                        {
                            int colLength = dr["LOCATION_NAME"].ToString().Length;
                            int blankLength = maxLength - colLength;
                            string strBlank = "";
                            for (int i = 0; i < blankLength; i++)
                            {
                                strBlank += " ";
                            }
                            strName += strBlank + dr["LOCATION_NAME"].ToString() + "： " + dr["WORKER_NAME"].ToString() + "\r\n";
                        }
                        LabelControl1.Text = strName;
                    }

                    string seatPath = path;
                    if (File.Exists(seatPath))
                    {
                        picTop3.Visible = true;
                        LabelControl1.Visible = false;
                        picTop3.Load(seatPath);
                        //picProcess1.Load(QualityPath1);
                    }

                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 加载扫描显示数据
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="dtShowHeader"></param>
        /// <param name="pcBottom"></param>
        private static void ShowProcessList(string UserName,DataTable dtShowHeader,PanelControl pcBottom, PanelControl pcMid_L, int maxStandertime, int  minStandertime, int standertime, int productTime, double iCycletime,bool IsPress)
        {
            if (IsPress)
            {
                int i = 0;
                foreach (Control c in pcBottom.Controls)
                {
                    if (c is GroupControl)
                    {
                        GroupControl g = c as GroupControl;
                        foreach (Control p in g.Controls)
                        {
                            if (p is Lamex.Library.UserCotrolUI.FrmSeatControlUI)
                            {
                                FrmSeatControlUI uc = p as FrmSeatControlUI;

                                foreach (DataRow dr in dtShowHeader.Rows)
                                {
                                    if (uc.Tag.ToString() == dr["LOCATION_NAME"].ToString())
                                    {
                                        //if (uc.IsHandleCreated)
                                        //    uc.Invoke(new Action(() =>
                                        //    {

                                        g.Text = uc.Name;
                                        bool Isvalue = true;
                                        bool ReValue = false;
                                        uc.ShowProcessList(dr["LOCATION_ORDER"].ToString(), maxStandertime, minStandertime, standertime, productTime, UserName, ref Isvalue, ref ReValue);
                                        if (ReValue != false)
                                        {
                                            if (Isvalue == true)
                                            {
                                                g.LookAndFeel.UseDefaultLookAndFeel = false;
                                                g.LookAndFeel.SkinMaskColor = Color.Green;
                                            }
                                            else
                                            {
                                                g.LookAndFeel.UseDefaultLookAndFeel = false;
                                                g.LookAndFeel.SkinMaskColor = Color.Red;
                                            }
                                        }
                                        //}));
                                    }

                                }

                            }
                        }
                    }
                }


                foreach (Control c in pcMid_L.Controls)
                {
                    if (c is GroupControl)
                    {
                        GroupControl g = c as GroupControl;
                        foreach (Control p in g.Controls)
                        {
                            if (p is FrmQualityPassRate)
                            {
                                FrmQualityPassRate uc = p as FrmQualityPassRate;
                                uc.ShowProcessList("1", 200, UserName);
                            }
                            else if (p is FrmProductQualityControlUI)
                            {
                                FrmProductQualityControlUI uc = p as FrmProductQualityControlUI;
                                uc.ShowProcessList("1", 200, UserName);
                            }
                            else if (p is FrmProductRate)
                            {
                                FrmProductRate uc = p as FrmProductRate;
                                uc.ShowProcessList("1", int.Parse(iCycletime.ToString()), UserName);
                            }
                            else if (p is FrmOEEControlUI)
                            {
                                FrmOEEControlUI uc = p as FrmOEEControlUI;
                                uc.ShowProcessList("1", 200, UserName);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Control c in pcBottom.Controls)
                {
                    if (c is GroupControl)
                    {
                        GroupControl g = c as GroupControl;
                        foreach (Control p in g.Controls)
                        {
                            if (p is LabelControl)
                            {
                                LabelControl uc = p as LabelControl;

                                foreach (DataRow dr in dtShowHeader.Rows)
                                {
                                    if (uc.Name == dr["LOCATION_NAME"].ToString())
                                    {
                                        DataTable _dt = BaseBuildSql.GetDataTableBySql(@"
                                                    select a.LOCATION_NAME,ISNULL( b.SCAN_QTY,0) SCAN_QTY  from HR_Station_Info a
                                                        left join  (select LOCATION_CODE  ,STATION_NAME,case when  ISNULL( sum(ISNULL( SCAN_QTY,0)),0)=0 then 0 else sum(ISNULL( SCAN_QTY,0)) end  as SCAN_QTY  from [dbo].[HR_Scan_Record] where BARCODE like 'PL%' and CONVERT(nvarchar(10),SCAN_TIME,120)=CONVERT(nvarchar(10),GETDATE(),120) and LOCATION_CODE='" + uc.Name + "' and STATION_NAME='" + UserName + @"'
                                                    group by LOCATION_CODE ,STATION_NAME) b on a.LOCATION_NAME=b.LOCATION_CODE and b.STATION_NAME=a.STATION_NAME
                                                    where a.LOCATION_NAME='" + uc.Name + "'  and a.STATION_NAME='" + UserName + @"'");

                                        if (_dt.Rows.Count != 0)
                                        {
                                            uc.Text = _dt.Rows[0]["SCAN_QTY"].ToString();
                                        }
                                        else
                                            uc.Text = "0";

                                  
                                    }

                                }

                            }
                        }
                    }
                }
            }
        }

        public static void ShowProcessInvokeList(string UserName, DataTable dtShowHeader, PanelControl pcBottom, PanelControl pcMid_L, int maxStandertime, int minStandertime, int standertime, int productTime, double iCycletime, bool IsPress)
        {
            if (IsPress)
            {
                int i = 0;
                foreach (Control c in pcBottom.Controls)
                {
                    if (c is GroupControl)
                    {
                        GroupControl g = c as GroupControl;
                        foreach (Control p in g.Controls)
                        {
                            if (p is Lamex.Library.UserCotrolUI.FrmSeatControlUI)
                            {
                                FrmSeatControlUI uc = p as FrmSeatControlUI;

                                foreach (DataRow dr in dtShowHeader.Rows)
                                {
                                    if (uc.Tag.ToString() == dr["LOCATION_NAME"].ToString())
                                    {
                                        uc.Visible = true;
                                        if (uc.IsHandleCreated)
                                            uc.Invoke(new Action(() =>
                                            {

                                                g.Text = uc.Name;
                                                bool Isvalue = true;
                                                bool ReValue = false;
                                                uc.ShowProcessList(dr["LOCATION_ORDER"].ToString(), maxStandertime, minStandertime, standertime, productTime, UserName, ref Isvalue, ref ReValue);
                                                if (ReValue != false)
                                                {
                                                    if (Isvalue == true)
                                                    {
                                                        g.LookAndFeel.UseDefaultLookAndFeel = false;
                                                        g.LookAndFeel.SkinMaskColor = Color.Green;
                                                    }
                                                    else
                                                    {
                                                        g.LookAndFeel.UseDefaultLookAndFeel = false;
                                                        g.LookAndFeel.SkinMaskColor = Color.Red;
                                                    }
                                                }
                                            }));
                                    }

                                }

                            }
                        }
                    }
                }


                foreach (Control c in pcMid_L.Controls)
                {
                    if (c is GroupControl)
                    {
                        GroupControl g = c as GroupControl;
                        foreach (Control p in g.Controls)
                        {
                            if (p is FrmQualityPassRate)
                            {
                                FrmQualityPassRate uc = p as FrmQualityPassRate;
                                if (uc.IsHandleCreated)
                                    uc.Invoke(new Action(() =>
                                    {
                                        uc.ShowProcessList("1", standertime, UserName);
                                    }));
                               
                            }
                            else if (p is FrmProductQualityControlUI)
                            {
                                FrmProductQualityControlUI uc = p as FrmProductQualityControlUI;
                                if (uc.IsHandleCreated)
                                    uc.Invoke(new Action(() =>
                                    {
                                        uc.ShowProcessList("1", standertime, UserName);
                                    }));
                            }
                            else if (p is FrmProductRate)
                            {
                                FrmProductRate uc = p as FrmProductRate;
                                if (uc.IsHandleCreated)
                                    uc.Invoke(new Action(() =>
                                    {
                                        uc.ShowProcessList("1", int.Parse(iCycletime.ToString()), UserName);
                                    }));
                            }
                            else if (p is FrmOEEControlUI)
                            {
                                FrmOEEControlUI uc = p as FrmOEEControlUI;
                                if (uc.IsHandleCreated)
                                    uc.Invoke(new Action(() =>
                                    {
                                        uc.ShowProcessList("1", standertime, UserName);
                                    }));
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Control c in pcBottom.Controls)
                {
                    if (c is GroupControl)
                    {
                        GroupControl g = c as GroupControl;
                        foreach (Control p in g.Controls)
                        {
                            if (p is LabelControl)
                            {
                                LabelControl uc = p as LabelControl;

                                foreach (DataRow dr in dtShowHeader.Rows)
                                {
                                    if (uc.Name == dr["LOCATION_NAME"].ToString())
                                    {
                                        DataTable _dt = BaseBuildSql.GetDataTableBySql(@"
                                                    select a.LOCATION_NAME,ISNULL( b.SCAN_QTY,0) SCAN_QTY  from HR_Station_Info a
                                                        left join  (select LOCATION_CODE  ,STATION_NAME,case when  ISNULL( sum(ISNULL( SCAN_QTY,0)),0)=0 then 0 else sum(ISNULL( SCAN_QTY,0)) end  as SCAN_QTY  from [dbo].[HR_Scan_Record] where BARCODE like 'PL%' and CONVERT(nvarchar(10),SCAN_TIME,120)=CONVERT(nvarchar(10),GETDATE(),120) and LOCATION_CODE='" + uc.Name + "' and STATION_NAME='" + UserName + @"'
                                                    group by LOCATION_CODE ,STATION_NAME) b on a.LOCATION_NAME=b.LOCATION_CODE and b.STATION_NAME=a.STATION_NAME
                                                    where a.LOCATION_NAME='" + uc.Name + "'  and a.STATION_NAME='" + UserName + @"'");

                                        if (_dt.Rows.Count != 0)
                                        {
                                            uc.Text = _dt.Rows[0]["SCAN_QTY"].ToString();
                                        }
                                        else
                                            uc.Text = "0";


                                    }

                                }

                            }
                        }
                    }
                }
            }
        }

        private static void ShowChartList()
        {

        }


        public static void IsPieVisible(PanelControl pcBottom)
        {
            foreach (Control c in pcBottom.Controls)
            {
                if (c is GroupControl)
                {
                    GroupControl g = c as GroupControl;
                    foreach (Control p in g.Controls)
                    {
                        if (p is Lamex.Library.UserCotrolUI.FrmSeatControlUI)
                        {
                            FrmSeatControlUI uc = p as FrmSeatControlUI;
                            if (uc.IsHandleCreated)
                                uc.Invoke(new Action(() =>
                                {
                                    uc.Visible = false;
                                }));
                        }
                        if (p is PictureBox)
                        {
                            PictureBox uc = p as PictureBox;
                            //uc.Visible = true;
                            if (uc.IsHandleCreated)
                                uc.Invoke(new Action(() =>
                                {
                                    uc.Visible = true;
                                }));
                        }
                            
                    }
                }
            }
        }


        public static void IsPicVisible(PanelControl pcBottom)
        {
            foreach (Control c in pcBottom.Controls)
            {
                if (c is GroupControl)
                {
                    GroupControl g = c as GroupControl;
                    foreach (Control p in g.Controls)
                    {
                        if (p is Lamex.Library.UserCotrolUI.FrmSeatControlUI)
                        {
                            FrmSeatControlUI uc = p as FrmSeatControlUI;
                            if (uc.IsHandleCreated)
                                uc.Invoke(new Action(() =>
                                {
                                    uc.Visible = true;
                                }));
                        }
                        if (p is PictureBox)
                        {
                            PictureBox uc = p as PictureBox;
                            //uc.Visible = false;
                            if (uc.IsHandleCreated)
                                uc.Invoke(new Action(() =>
                                {
                                    uc.Visible = false;
                                }));
                        }

                    }
                }
            }
        }


        public static void LoadPicPath(PanelControl pcBottom,string UserName, string _StationName)
        {
            foreach (Control c in pcBottom.Controls)
            {
                if (c is GroupControl)
                {
                    GroupControl g = c as GroupControl;
                    foreach (Control p in g.Controls)
                    {
                        if (p is FrmSeatControlUI)
                        {
                            FrmSeatControlUI uc = p as FrmSeatControlUI;
                            uc.Visible = false;
                        }
                        if (p is PictureBox)
                        {
                            PictureBox uc = p as PictureBox;
                            uc.Visible = true;
                            string Path = @"\\tx-fs10\TX-FS1\LAMEX\MES\SysSource\Image\Quality\" + UserName + @"\" + _StationName + "_0" + p.TabIndex.ToString() + ".PNG";
                            if(File.Exists(Path))
                                uc.Load(Path);
                        }

                    }
                }
            }
        }

    }
}
